﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Tosi
{
    class Street
    {
        private Point start;
        private Point end;
        private Junction myJunction;
        private double[] phi;
        private int maxCars;
        private int initMaxCars()
        {
            return (int)((int)Math.Sqrt(Math.Pow((end.getX() - start.getX()), 2) + Math.Pow(end.getY() - start.getY(), 2))) / Var.CarOffset;
        }
        public List<Car> cars;
        public Light myLight;

        public Street(Point st, Point en, int id)
        {
            start = new Point(st.getX(), st.getY());
            end = new Point(en.getX(), en.getY());
            cars = new List<Car>();
            phi = new double[2];
            phi = Var.gr.getStreetPhi(id);
            maxCars = initMaxCars();
            myLight = new Light(id, this);
        }
        public void carIn(Car theCar)
        {
            cars.Add(theCar);
        }
        public void carOut(Car theCar)
        {
            cars.Remove(theCar);
        }
        public Point getStart()
        {
            return start;
        }
        public Point getEnd()
        {
            return end;
        }
        public void setMyJunction(ref Junction set)
        {
            myJunction = set;
        }
        public Junction getMyJunction()
        {
            return myJunction;
        }
        public double getCosPhi() {
            return phi[0];
        }
        public double getSinPhi() {
            return phi[1];
        }
        public int getMaxCars() {
            return maxCars;
        }
        public Light getMyLight() { 
            return myLight;
        }

        public List<Car> getCars()
        {
            return cars;
        }
    }
}
